#ifndef __HLINK_PACKAGES_H__
#define __HLINK_PACKAGES_H__

#include "securec.h"
#include "omip.h"

/*文件名长度和文件路径长度*/

#define  FILE_NAME_LENGTH                100
#define  FILE_NAME_PATH_LENGTH           100
#define  FILE_NAME_TOTAL_LENGTH          200

#define         EFS_MAGIC_NUM_LENGTH       4
#define         EFS_PRODUCT_NAME_LENGTH    12
#define         EFS_PRODUCT_VERSION_LENGTH      32
#define         EFS_RST_LENGTH            12
#define         EFS_FILE_TYPE_LEN               32

#define STOP_UPGRADE     0
#define CONTINUE_UPGRADE 1

typedef struct tag_struct_efs
{
    uint8_t         magic_num[EFS_MAGIC_NUM_LENGTH+1];
    uint8_t         reserved1;
    uint16_t        efs_version;
    char            product_name[EFS_PRODUCT_NAME_LENGTH+1];
    char            product_version[EFS_PRODUCT_VERSION_LENGTH+1];
    char            file_type[EFS_FILE_TYPE_LEN];
    uint16_t        year;
    uint8_t         month;
    uint8_t         day;
    uint8_t         hour;
    uint8_t         minute;
    uint8_t         second;
    uint8_t         reserved2;
    uint16_t        reserved3;
    uint32_t        total_len;
    uint32_t        code_len;
	char 			checksum[64];
    uint16_t        code_crc;
    uint16_t        efs_crc;
}SEFS;

/* 定义EFS中FileType的枚举 */

typedef enum tag_en_efs_filetype
{
    EFS_UNKNOWN_FILE_TYPE = 0x00,  /*  未知文件类型 */
    EFS_DEVICE_FIRMWARE = 0x01, /*  模组固件 */
    EFS_MCU_FIRMWARE = 0x02, /* 厂商MCU固件 */
    EFS_IOM_FIRMWARE = 0x03, /* 厂商IOM固件 */
    EFS_BT_FIRMWARE = 0x04, /* 厂商蓝牙固件 */
    EFS_LAST_FILE_TYPE
}EnEFSFileType;

typedef enum tag_firmware_upgrade_status
{
    UPGRADE_START,
    UPGRADE_END
}firmware_upgrade_status;

/*CreateBIN工具自己的版本号，注意字符串长度固定为5字节*/

#define  CREATEBINVER                   "1.0.1"
#define  BIN_PUB_HEAD_DES               "HX PRODUCT PACKAGE FILE"

#define MAX_SUB_FILE_NUM                10

/*资源文件头部宏定义*/
#define FILE_COPY_BUFFER_LEN            10240
#define FILE_SPACE_BUFFER_LEN           4
#define LOAD_BIN_SUBFILENAME_LEN        64
#define LOAD_BIN_FILEDESCS_LEN          32
#define LOAD_BIN_FILEVER_LEN            8
#define LOAD_BIN_PRODUCTNAME_LEN        32
#define LOAD_BIN_FILETIME_LEN           20
#define LOAD_BIN_FILERSV_LEN            8
#define LOAD_BIN_FILENAME_LEN           64 

typedef struct tagBINFILE_HEAD_FIXED
{
    char file_desc[LOAD_BIN_FILEDESCS_LEN+1];
    char file_ver[LOAD_BIN_FILEVER_LEN+1];
    char product_name[LOAD_BIN_PRODUCTNAME_LEN+1];
    char file_time[LOAD_BIN_FILETIME_LEN+1];
    uint32_t file_len;
    uint32_t sub_file_sum;
    uint32_t bin_head_size;
    uint8_t bin_head_rsv[LOAD_BIN_FILERSV_LEN];
}BINFILE_HEAD_FIXED_S;


typedef struct tagBIN_SUBFILE_HEAD
{
    char sub_file_name[LOAD_BIN_SUBFILENAME_LEN];
    char  file_type[EFS_FILE_TYPE_LEN];
    uint32_t sub_file_len;
    uint32_t sub_file_offset;
    uint32_t sub_file_head_size;
    uint8_t sub_file_rsv[4];
}BIN_SUBFILE_HEAD_S;

#endif /* __HLINK_PACKAGES_H__ */
